// pages/userEvaluation/userEvaluation.js
import api from "../../api/api"
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    userEval:{
      overallScore:"",
      timelinessScore:"",
      serviceScore:"",
      professionalScore:"",
      commentContent:"",
      shippingOrderNumber:"",
      id:""
    },
    isLoading: false
  },

  upUsereval(){
    let that=this
    if (that.data.userEval.overallScore && that.data.userEval.timelinessScore && that.data.userEval.serviceScore && that.data.userEval.professionalScore && that.data.userEval.commentContent) {
      let value = wx.getStorageSync('id')
      that.setData({
        'userEval.id':value 
      })
      that.getusereval()
    } else {
      wx.showToast({
        icon:'none',
        title: "请完善评价信息",
        duration: 2000
     });
    }
  },

  getusereval() {
    // 改变this指向
    let that = this;
    api.post('/app/evaluation/addEvaluation', that.data.userEval)
    .then(res => {
      if (res.code==200) {
        setTimeout(function() {
          wx.showToast({
            icon:'none',
            title: "评价成功",
            duration: 2000
         });
       }, 2000);
       wx.navigateBack()
      }else{
          wx.showToast({
            icon:'none',
            title: "评价失败",
            duration: 2000
         });
      }
    })
    .catch(err => {
    // wx.showToast({
    //   icon:'none',
    //   title: err.message,
    //   duration: 2000
    // })
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that =this
    let companyid = wx.getStorageSync('companyid')
    that.setData({
      'userEval.shippingOrderNumber':options.shippingOrderNumber
    })
  },

  onClickLeft() {
    wx.navigateBack()
  },

  onChange1(event) {
    let that=this
    that.setData({
      'userEval.overallScore':event.detail
    })
  },
  onChange2(event) {
    let that=this
    that.setData({
      'userEval.timelinessScore':event.detail
    })
  },
  onChange3(event) {
    let that=this
    that.setData({
      'userEval.serviceScore':event.detail
    })
  },
  onChange4(event) {
    let that=this
    that.setData({
      'userEval.professionalScore':event.detail
    })
  },

  changeInput(event){
    let that=this
    that.setData({
      'userEval.commentContent':event.detail
    })
  }
})